﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;

namespace WebApplication.Admins.Controls
{
    public partial class UCTaiKhoan : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Display();

            }
            lblTenDN.Visible = false;
            lblhoten.Visible = false;
            txtTimTenTK.Visible = false;
            txtHoTen.Visible = false;
            btnTim.Visible = false;
        }
        public void Display()
        {
            int howManyPages = 0;
            string ID = Request.QueryString["IDTaiKhoan"] ?? "";
            string page = Request.QueryString["Page"] ?? "1";
            string firstpage = "";
            string pageUrl = "";
            if (ID == "")
            {
                repTaiKhoan.DataSource = BLL.TaiKhoanBLL.Paging(page, out howManyPages);
                repTaiKhoan.DataBind();
                firstpage = BLL.LinkBLL.ToAdmin_TaiKhoan();
                pageUrl = LinkBLL.ToAdmin_TaiKhoan("{0}");
            }
            pagerTop.Show(int.Parse(page), howManyPages, firstpage, pageUrl, false);
            pagerBottom.Show(int.Parse(page), howManyPages, firstpage, pageUrl, true);
        }

        protected void btnXoa_Click(object sender, EventArgs e)
        {
            string Id = Request.Form["Id"] ?? "";
            if (Id != "")
            {
                foreach (string id in Id.Split(','))
                    BLL.TaiKhoanBLL.Xoa(Id);
                Display();
            }
        }

        protected void repTinTuc_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            //if (e.CommandName == "UpdateHienThi")
            //{
            //    string[] ag = e.CommandArgument.ToString().Split('_');
            //    TinTuc_BLL.CapNhatHienThi(ag[0], !Boolean.Parse(ag[1]));
            //    Display();
            //}

        }


        private void source()
        {
            repTaiKhoan.DataSource = TaiKhoanBLL.LayTatCa();
            repTaiKhoan.DataBind();
        }

        protected void btnTimKiem_Click(object sender, EventArgs e)
        {
            lblTenDN.Visible = true;
            lblhoten.Visible = true;
            txtTimTenTK.Visible = true;
            txtHoTen.Visible = true;
            btnTim.Visible = true;
        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            btnTim.Click += new EventHandler(btnTim_Click);
        }
        protected void btnTim_Click(object sender, EventArgs e)
        {
            if (txtHoTen.Text.Length > 0)
            {
                repTaiKhoan.DataSource = TaiKhoanBLL.TimKiemHoTen(txtHoTen.Text.Trim().ToLower());
                repTaiKhoan.DataBind();
            }
            else if (txtHoTen.Text.Length > 0)
            {
                repTaiKhoan.DataSource = TaiKhoanBLL.TimKiemTenTK(txtTimTenTK.Text.Trim().ToLower());
                repTaiKhoan.DataBind();
            }
            else

                if (txtHoTen.Text.Length > 0 || txtTimTenTK.Text.Length > 0)
                {
                    repTaiKhoan.DataSource = TaiKhoanBLL.TimKiem(txtHoTen.Text.Trim().ToLower(), txtTimTenTK.Text.Trim().ToLower());
                    repTaiKhoan.DataBind();
                }
        }
    }
}